#include <bits/stdc++.h>
using namespace std;
int n,ans,a[2005]; int choic[2005];
int check() {
    int lsta=0,lstb=0; int ret=0;
    for(int i=1;i<=n;++i) {
        if(choic[i]==0 && a[i]==a[lsta]) ret+=a[i];
        if(choic[i]==0) lsta=i;
        if(choic[i]==1 && a[i]==a[lstb]) ret+=a[i];
        if(choic[i]==1) lstb=i;
    }
    return ret;
}
inline void dg(int x) {
    if(x>n) {
        ans=max(ans,check());
        return ;
    }
    choic[x]=1;
    dg(x+1);
    choic[x]=0;
    dg(x+1);
}
int main() {
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T; cin >> T;
    for(int te=1;te<=T;++te) {
        cin >> n; ans=0;
        for(int i=1;i<=n;++i) cin >> a[i];
        dg(1);
        cout << ans << '\n';
    }
    return 0;
}